<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1>原料库库存综合查询</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label>项目编号</label>
                                    <input type="text" name="ityProCode" id="ityProCode"
                                           class="form-control"
                                           placeholder="请输入项目编号"  th:value="${projectCode}">
                                </div>
                                <div class="form-group">
                                    <label>项目名称</label>
                                    <input type="text" name="ityProName" id="ityProName"
                                           class="form-control"
                                           placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label>供应商</label>
                                    <input type="text" name="supplier" id="supplier"
                                           class="form-control"
                                           placeholder="请输入供应商">
                                </div>
                                <div class="form-group">
                                    <label>合同编号</label>
                                    <input type="text" name="contractNo" id="contractNo"
                                           class="form-control"
                                           placeholder="请输入合同编号">
                                </div>
                                <div class="form-group">
                                    <label>跟踪号</label>
                                    <input type="text"
                                           name="ityTrackCode"
                                           id="ityTrackCode"
                                           class="form-control"
                                           placeholder="请输入跟踪号">
                                </div>
                                <div class="form-group">
                                    <label>原料类型</label>
                                    <input type="text"
                                           id="matTypeName"
                                           name="matTypeName"
                                           class="form-control"
                                           placeholder="请输入原料类型">
                                </div>
                                <div class="form-group">
                                    <label>原料材质</label>
                                    <input id="matQualityName"
                                           type="text"
                                           name="matQualityName"
                                           class="form-control"
                                           placeholder="请输入原料材质">
                                </div>
                                <div class="form-group">
                                    <label>原料规格</label>
                                    <input id="matSpecName" type="text" name="matSpecName" class="form-control"
                                           placeholder="请输入原料规格">
                                </div>
                                <div class="form-group">
                                    <label>宽度</label>
                                    <input id="matWidth" type="number" step="0.1" name="matWidth"
                                           class="form-control"
                                           placeholder="请输入原料宽度">
                                </div>
                                <div class="form-group">
                                    <label>长度</label>
                                    <input id="matLength" type="number" step="0.1" name="matLength"
                                           class="form-control"
                                           placeholder="请输入原料长度">
                                </div>
                                <div class="form-group">
                                    <label>米重/厚度</label>
                                    <input id="matHeight" type="number" step="0.1" name="matHeight"
                                           class="form-control"
                                           placeholder="请输入原料米重/厚度">
                                </div>
                                <div class="form-group">
                                    <label>在库类型</label>
                                    <select id="ityInType" name="ityInType" class="form-control">
                                        <option value="1" th:selected="${ityInType == 1}">库存在库</option>
                                        <option value="2" th:selected="${ityInType == 2}">项目在库</option>
                                        <option value="" th:selected="${ityInType == ''}">全部</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>
                                        原料分类
                                    </label>
                                    <select id="materialKind" name="materialKind" class="form-control ">
                                        <option value="型材">型材&nbsp;&nbsp;</option>
                                        <option value="板材">板材&nbsp;&nbsp;</option>
                                        <option value="" selected="selected">全部</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label>库位</label>
                                    <select id="whiIdList" name="whiIdList"
                                            class="form-control selectpicker"
                                            data-live-search="true"
                                            data-actions-box="true"
                                            onchange="changeWhiIdListStr(this)"
                                            multiple>
                                        <option th:each="type:${warehouse}" th:value="${type.whiId}"
                                                th:text="${type.whiName}"
                                                th:selected="${type.whiType eq '原料库'}"></option>
                                    </select>
                                    <input name="whiIdListStr" type="hidden" th:value="${warehouseStr}" style="display:none">
                                </div>
                                <div class="form-group">
                                    <label>是否可串料</label>
                                    <select name="prodChaMat"
                                            class="form-control">
                                        <option selected="selected" value="-1">全部</option>
                                        <option value="0">是</option>
                                        <option value="1">否</option>
                                    </select>
                                    <input name="whiIdListStr" type="hidden" style="display:none">
                                </div>
                                <button type="button" class="btn btn-success pull-right" id="btn-search">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="row" id="toolbar">
                    <div class="form-inline">
                        <button type="button" id="btn_exportExcel"
                                shiro:hasPermission="matinv:matinvquery:export"
                                class="btn btn-primary">
                            导出
                        </button>
                        <img th:src="@{/img/downloadding.gif}" id="btn_tips" style="display: none"/>
                    </div>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"  style="word-break:break-all; word-wrap:break-all;"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var table;

    /**
     * 更改传到后台的值
     * */
    function changeWhiIdListStr(obj){
        $("#queryForm [name='whiIdListStr']").val( $(obj).val().join(','));
    }


    /**
     * 数据初始化
     */
    function inv(){
        $("#queryForm [name='whiIdListStr']").val( $("#queryForm [name='whiIdList']").val().join(','));
        table = js.table.init({
            url: ctx + "matInvManage/complex/list",
            showExport: false,
            queryData: {
                ityProCode: $("#ityProCode").val(),
                ityProName: $("#ityProName").val(),
                ityTrackCode: $("#ityTrackCode").val(),
                matTypeName: $("#matTypeName").val(),
                matQualityName: $("#matQualityName").val(),
                matSpecName: $("#matSpecName").val(),
                matWidth: $("#matWidth").val(),
                matLength: $("#matLength").val(),
                matHeight: $("#matHeight").val(),
                ityInType: $("#ityInType").val(),
                materialKind: $("#materialKind").val(),
                whiIdListStr:$("#queryForm [name='whiIdListStr']").val()
            },
            onLoadSuccess: function (result) {
                $('#btn-search').prop('disabled', false).removeClass('disabled');
            },
            pageSize: 300,
            showColumns: true,
            showExport: false,
            columns: [
                {
                    title: '序号', field: 'odaId', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: '类型', field: 'matTypeName', width: '90'},
                {title: '材质', field: 'matQualityName', width: '90'},
                {title: '规格', field: 'matSpecName', width: '90'},
                {title: '宽度', field: 'matWidth', width: '70'},
                {title: '长度', field: 'matLength', width: '70'},
                {title: '米重/<br>厚度', field: 'matHeight', width: '70'},
                {title: '数量', field: 'ityNum', width: '70'},
                {
                    title: '单价<br>（元）', field: 'ityPrice', width: '90',
                    formatter: function (value, row, index) {
                        if (hasP("matinv:amount:view")) {
                            if (value == undefined || value == null || value == 0) {
                                return "--"
                            } else {
                                return value;
                            }
                        } else {
                            return '***';
                        }
                    }
                },
                {
                    title: '金额<br>（元）', field: 'ityAmount', width: '100',
                    formatter: function (value, row, index) {
                        if (hasP("matinv:amount:view")) {
                            if (value == undefined || value == null || value == 0) {
                                return "--"
                            } else {
                                return value;
                            }
                        } else {
                            return '***';
                        }
                    }
                },
                {title: '理论重量', field: 'ityWeight', width: '100'},
                {title: '跟踪号', field: 'ityTrackCode', width: '110'},
                {title: '特殊说明', field: 'itySpec', width: '75'},
                {title: '项目编号', field: 'ityProCode', width: '95'},
                {title: '项目名称', field: 'ityProName', width: '300'},
                {title: '供应商', field: 'supplier', width: '90'},
                {title: '合同编号', field: 'contractNo', width: '90'},
                {title: '回货时间', field: 'ityBackDate', width: '110'},
                {
                    title: '在库类型', field: 'ityInType', width: '95',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '库存在库';
                        } else if (value === 2) {
                            return '项目在库';
                        }
                    }
                },
                {title: '库位', field: 'stockName', width: '80'},
                {title: '区位', field: 'ityPosition', width: '80'},
                {
                    title: '是否可串料', field: 'prodChaMat', width: '80',
                    formatter: function (value, row, index) {
                        if (value === 0) {
                            return '是';
                        } else if (value === 1) {
                            return '否';
                        }
                    }
                },
            ],
            /*onLoadSuccess: function () {
                if (!hasP("matinv:amount:view")) {
                    table.bootstrapTable('hideColumn', 'ityPrice');
                    table.bootstrapTable('hideColumn', 'ityAmount');
                }
            },*/
            rowStyle: function (row, index) {
                if (row.itySpec != null && row.itySpec.indexOf("不合格") >= 0) {
                    return {css: {"color": "red"}}
                } else {
                    return {css: {"color": "black"}}
                }
            }
        });
    }
    $(function () {
        inv();


        /** 表格搜索 */
        $("#btn-search").click(function () {
            // let vvv = $("#whiIdList").val();
            $('#btn-search').prop('disabled', true).addClass('disabled');
            $("#bootstrap-table").bootstrapTable('destroy');
            inv();
            // js.table.search(table);
        });
        /**
         *@Description: 导出
         */
        $("#btn_exportExcel").click(function () {
            $("#queryForm [name='whiIdListStr']").val( $("#queryForm [name='whiIdList']").val().join(','));
            $("#btn_exportExcel").hide();
            $("#btn_tips").show();
            js.post({
                url: ctx + "matInvManage/complex/exportExcel",
                data: $("#queryForm").serialize(),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        location.href=ctx + "purWarQuery/downloadExportExcel/"+result.data;
                    } else {
                        js.modal.warning("导出失败，请联系管理员！");
                    }
                    $("#btn_tips").hide();
                    $("#btn_exportExcel").show();
                }
            })
        });
    });
</script>
</body>
</html>
